<?php

namespace Common\Controller;

use Think\Controller;
use Admin\Model;

/**
 * 后台公用基类
 * 作者 : Alang
 * 时间 : 2019年6月26日16:23:00
 */
class AdminController extends Controller {

    function _initialize() {
        if(empty($_SESSION['account_user_id'])){
            redirect("/Admin/Login/index");
        }
    }

    // 是否登录
    public function isLogin($statusCode) {
        if (!isset($statusCode) || !empty($statusCode)) {
            $this->ajaxReturn(array("code" => 10010, 'msg' => '登录失效，请重新登录'));
        } else {
            return true;
        }
    }

    public function getMenus($loginType = 2) {
        $menusModel = new \Admin\Model\MenusModel();
        $where['type'] = $loginType;
        $where['inuse'] = 1;
        $result = $menusModel->getList($where);
        $r = $this->getTree($result, 0);
        return $r;
    }
 
    // 无限极分类
    public function getTree($data, $pid) {
        $list = array();
        foreach ($data as $value) {
            if ($value['parent_id'] == $pid) {
                $value['child'] = $this->getTree($data, $value['id']);
                $list[] = $value;
            }
        }
        return $list;
    }

}
